<template>
  <div class="login-page">
    <div class="login-container">
      <div class="login-box">
        <div class="login-header">
          <img src="@/assets/logo.png" alt="Logo" class="logo">
          <h2>欢迎登录</h2>
        </div>
        
        <el-form 
          ref="loginForm"
          :model="loginForm"
          :rules="rules"
          class="login-form"
        >
          <el-form-item prop="username">
            <el-input
              v-model="loginForm.username"
              placeholder="用户名/手机号/邮箱"
              prefix-icon="User"
            />
          </el-form-item>
          
          <el-form-item prop="password">
            <el-input
              v-model="loginForm.password"
              type="password"
              placeholder="密码"
              prefix-icon="Lock"
              show-password
            />
          </el-form-item>
          
          <div class="form-options">
            <el-checkbox v-model="rememberMe">记住我</el-checkbox>
            <el-link type="primary" :underline="false" @click="handleForgotPassword">
              忘记密码？
            </el-link>
          </div>
          
          <el-button 
            type="primary" 
            class="login-button"
            :loading="loading"
            @click="handleLogin"
          >
            登录
          </el-button>
          
          <div class="other-options">
            <span>还没有账号？</span>
            <el-link type="primary" :underline="false" @click="handleRegister">
              立即注册
            </el-link>
          </div>
        </el-form>
        
        <div class="social-login">
          <div class="divider">
            <span>其他登录方式</span>
          </div>
          <div class="social-icons">
            <el-button circle>
              <el-icon><WechatFilled /></el-icon>
            </el-button>
            <el-button circle>
              <el-icon><AlipayCircleFilled /></el-icon>
            </el-button>
            <el-button circle>
              <el-icon><Message /></el-icon>
            </el-button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { defineComponent, ref, reactive } from 'vue';
import { useRouter } from 'vue-router';
import { ElMessage } from 'element-plus';
import { User, Lock, WechatFilled, AlipayCircleFilled, Message } from '@element-plus/icons-vue';

export default defineComponent({
  name: 'Login',
  components: {
    User,
    Lock,
    WechatFilled,
    AlipayCircleFilled,
    Message
  },
  setup() {
    const router = useRouter();
    const loginForm = reactive({
      username: '',
      password: ''
    });
    
    const rules = {
      username: [
        { required: true, message: '请输入用户名', trigger: 'blur' }
      ],
      password: [
        { required: true, message: '请输入密码', trigger: 'blur' },
        { min: 6, message: '密码长度不能小于6位', trigger: 'blur' }
      ]
    };
    
    const loading = ref(false);
    const rememberMe = ref(false);
    
    const handleLogin = async () => {
      loading.value = true;
      try {
        // 模拟登录请求
        await new Promise(resolve => setTimeout(resolve, 1000));
        ElMessage.success('登录成功');
        router.push('/');
      } catch (error) {
        ElMessage.error('登录失败，请重试');
      } finally {
        loading.value = false;
      }
    };
    
    const handleRegister = () => {
      router.push('/register');
    };
    
    const handleForgotPassword = () => {
      router.push('/forgot-password');
    };
    
    return {
      loginForm,
      rules,
      loading,
      rememberMe,
      handleLogin,
      handleRegister,
      handleForgotPassword
    };
  }
});
</script>

<style lang="scss">
.auth-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: $background-color-base;
  padding: $spacing-extra-large $spacing-base;
}

.login-container {
  width: 100%;
  max-width: 420px;
  padding: $spacing-base;
}

.login-box {
  background-color: $background-color-white;
  padding: $spacing-extra-large;
  border-radius: $border-radius-large;
  box-shadow: $box-shadow-base;
}

.login-header {
  text-align: center;
  margin-bottom: $spacing-extra-large;

  .logo {
    width: 120px;
    margin-bottom: $spacing-base;
  }

  h2 {
    font-size: $font-size-extra-large;
    color: $text-primary;
    margin: 0;
  }
}

.login-form {
  .login-button {
    width: 100%;
    margin-top: $spacing-base;
  }
}

.form-options {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: $spacing-base;
}

.other-options {
  margin-top: $spacing-base;
  text-align: center;
  color: $text-regular;
}

.social-login {
  margin-top: $spacing-extra-large;

  .divider {
    display: flex;
    align-items: center;
    margin: $spacing-large 0;
    color: $text-secondary;

    &::before,
    &::after {
      content: '';
      flex: 1;
      height: 1px;
      background-color: $border-color-light;
    }

    span {
      padding: 0 $spacing-base;
    }
  }

  .social-icons {
    display: flex;
    justify-content: center;
    gap: $spacing-large;

    .el-button {
      font-size: 24px;
    }
  }
}

@media screen and (max-width: 480px) {
  .login-container {
    padding: $spacing-small;
  }

  .login-box {
    padding: $spacing-large;
  }
}
</style> 